<%@ page language="java" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>服务指标配置列表</title>
    <%@ include file="/WEB-INF/pages/common/meta.jsp" %>
    <%@ include file="/WEB-INF/pages/common/common.jsp" %>
    <link rel="stylesheet" type="text/css" href="${ctx}/uce/themes/icon.css"/>
</head>
<body>
<script type="text/javascript">
	/***
 * @date 2018-05-23
 * @author zhaocan
 * @desc  工单类型管理列表
 * */
//页面加载
var url;
var level = '';
var levelTypeStatus = '';
var targetId = '';//要去除的id
$(function() {

    //初始化数据字典
    var params = {
        url: G_CTX_PATH + "/dictData/findByTypesCodes.do"
    };
    initDictDatas("WORKORDER_KIND,WORKORDER_TYPE_LEVEL",params);//kindForQuery
    setCsSmOrderType();
    uceDictCombobox("kindForQuery","WORKORDER_KIND",{});
    //初始化工单类型/工单子类型
    var orderTypeParam = {
    };
	//加载 类型下拉框
    $('#type').uceCombobox({
        width : 155,
        editable : false,
        data : [{
        	 'value' : '',
             'text' : '全部',
             "selected" : true
        }, {
            'value' : '1',
            'text' : '一级',
        },{
            'value' : '2',
            'text' : '二级'
        },{
            'value' : '3',
            'text' : '三级'
        }]
    });
    
    //加载客服服务工单全部列表
    loadDataGrid();
});

//加载客服服务类工单全部列表数据
function loadDataGrid(){
    var columns = [[{field : 'idStr',title : '',hidden:true},
        {field:'deal',title: '操作',align:'center',width: 80,formatter:function(value,rec,index){
            var ret="";
            ret='<a class="icon-line iconfont uce-edit" title="编辑"  onclick="editCsWoCustSer(\''+index+'\')" href="javascript:void(0)"></a>';
            return ret;
        }
        },
        {field : 'id',title : 'id',width : 50,hidden:true},
        {field : 'firstType',title : '所属一级类型编码',width : 120},
        {field : 'firstTypeName',title : '所属一级类型名称',align:'center',width : 150},
        {field : 'secondeType',title : '所属二级类型编码',width : 120},
        {field : 'secondeTypeName',title : '所属二级类型名称',align:'center',width : 150},
        {field : 'typeCode',title : '类型编码',width : 90},
        {field : 'name',title : '类型名称',align:'center',width : 150},
        {field : 'type',title : '工单类型',align:'center',width : 80,formatter:typeName},
        {field : 'problemType',title : '问题件类型',width : 80,formatter:  function (value) {
                if(value == 1){
                	return "乾坤问题件类型";
                }if(value == 2){
                	return "ICS手工创建";
                }
            }},
        {field : 'startFlag',title : '是否启用',align:'center',width : 80,formatter:  function (value) {
                if(value == 0){
                	return "未启用";
                }if(value == 1){
                	return "已启用";
                }
            }},
        {field : 'validTime',title : '有效期(天)',align:'center',width : 80},
        {field : 'remarks',title : '备注',align:'center',width : 150},
    ]];
    var dataGridParams = {
        url : G_CTX_PATH+'/cs/CsSmOrderType/findCsSmOrderTypeByPage.do',
        pageSize : 10,
        toolbar : '#csSmOrderTypeSer',
        singleSelect : 'true',
        fitColumns : 'true'
    }
    newloadGrid('dgCsSmOrderTypeSer', columns, dataGridParams);
}

//查询
function findCsSmOrderTypeData() {
    $('#dgCsSmOrderTypeSer').datagrid('load', serializeFormObj("formFindCsSmOrderType"));
}

//查询条件重置
function resetQueryForm(){
    $("#formFindCsSmOrderType").form('reset');
}

function typeName(value){
	if(value == null){
		return ""
	}
	if(value == 1){
		return "一级";
	}if(value == 2){
		return "二级";
	}if(value == 3){
		return "三级";
	}
}

//编辑
function editCsWoCustSer(index){
    commomAdd();
    var rows = $("#dgCsSmOrderTypeSer").datagrid("getData").rows;
    var row = rows[index];
    var id =row.idStr;
    var url = G_CTX_PATH+'/cs/CsSmOrderType/findById.do';
    uceAjax(url,{'id':id},function (result) {
        var rel = result.data;
        if(rel != null){//如果查到数据
            $("#typeCode").textbox('setValue', rel.typeCode);
            $("#typeName").textbox('setValue', rel.name);
            $('#typeCode').textbox('readonly');
            $("#smOrderTypeId").val(rel.idStr);
            $("#orderLevel").combobox('setValue', rel.type);
            level = rel.type;//设置进入编辑框的初始的level值
            targetId = rel.idStr;//设置可能要删除的id
            $("#kind").combobox('setValue', rel.kind);
            $("#remarks").textbox('setValue', rel.remarks);
            $('#parentIdCombobox').combobox('readonly');
            $('#secondeIdCombobox').combobox('readonly');
            $('#orderLevel').combobox('readonly');
            $('#kind').combobox('readonly');
            if(rel.type == 2){//如果不为空，则是二级
                $("#parentIdCombobox").combobox('setValue', rel.parentIdStr);
                $("#secondeIdCombobox").combobox('setValue', '');
                //$('#problemType').combobox('readonly');
                //$('#startFlag').combobox('readonly');
                if(rel.startFlag == 0){
                	$("#startFlag").combobox('setValue', '未启用');
                }
                if(rel.startFlag == 1){
                	$("#startFlag").combobox('setValue', '已启用');
                }
                if(rel.problemType == 1){
                	$("#problemType").combobox('setValue', '乾坤问题件类型');
                }
                if(rel.problemType == 2){
                	$("#problemType").combobox('setValue', 'ICS手工创建');
                }
                $("#validTime").textbox('setValue', rel.validTime);
                $("#formCsSmOrderType #pOrderTypeTr").show();
                $("#formCsSmOrderType #pOrderTypeSec").hide();
            }else if(rel.type == 1){//否则为一级
                $("#parentIdCombobox").combobox('setValue', '');
                $("#secondeIdCombobox").combobox('setValue', '');
                $("#formCsSmOrderType #pOrderTypeTr").hide();
                $("#formCsSmOrderType #pOrderTypeSec").hide();
            }else if(rel.type == 3){//否则为一级
                $("#secondeIdCombobox").combobox('setValue', rel.parentIdStr);
                $("#parentIdCombobox").combobox('setValue', '');
                $("#formCsSmOrderType #pOrderTypeTr").hide();
                $("#formCsSmOrderType #pOrderTypeSec").show();
            }
            editCsSmOrderType();
        }
    },"POST");
}

//删除
function deleteCsWoCustSer(index){
    var rows = $("#dgCsSmOrderTypeSer").datagrid("getData").rows;
    var row = rows[index];
    var id =row.idStr;
    uceAjax(G_CTX_PATH+"/cs/CsSmOrderType/del.do",{id:id},function (result) {
        if(result.data == 1) {
            showInfoTip("删除成功", "", 2000);
            findCsSmOrderTypeData();
            cancle();
        }else if(result.data == 0){
            showInfoTip("删除失败", "", 2000);
            findCsSmOrderTypeData();
        }else if(result.data == 2){
            showInfoTip("当前类型下存在子类型，请先删除所属子类型", "", 2000);
            findCsSmOrderTypeData();
        }
    },"POST");
}

//新增工单
function addCsSmOrderType() {
    $('#problemType').combobox('readonly',false);
    $('#startFlag').combobox('readonly',false);
    $('#typeCode').textbox('readonly',false);
    $('#parentIdCombobox').combobox('readonly',false);
    $('#secondeIdCombobox').combobox('readonly',false);
    commomAdd();
    openCsSmOrderType();
}

//保存角色
function saveOrderType() {
    var status = '0';
    var levelType = $("#orderLevel").combobox('getValue');
    if(level == '1' && levelType == '2'){//如果是一级变成二级，则进行校验
        level = '';//清空遗留数据
        var parentId = $("#smOrderTypeId").val();
        var data = {'parentId':parentId};
        $.ajax({
            type : "POST",
            url : G_CTX_PATH + "/cs/CsSmOrderType/findByParentId.do",
            data : data,
            async : false,
            success : function(result) {//返回数据根据结果进行相应的处理
                if (result.data.length > 0) {
                    showInfoTip("该工单类型下有子工单类型,不予许修改,请先删除子工单", "", 2000);
                    status = '1';
                   }
               }
             })
    }
    if(status == '1'){
        status = '0';
        cancle();//关闭弹框
        return ;
    }
    var data = serializeFormObj("formCsSmOrderType");
    if(data.problemType == '乾坤问题件类型'){
    	data.problemType = 1;
    }
    if(data.problemType == 'ICS手工创建'){
    	data.problemType = 2;
    }
    if(data.startFlag == '未启用'){
    	data.startFlag = 0;
    }
    if(data.startFlag == '已启用'){
    	data.startFlag = 1;
    }
    level = '';//清空遗留数据
    levelTypeStatus = '';//清空数据
    if($("#formCsSmOrderType").form("validate")){
        uceAjax(url,data,function (result) {
            if(result.data > 0){
                closeDialog("dlgCsSmOrderType");
                showInfoTip("操作成功", "", 2000);
                $('#formCsSmOrderType').form('clear');//清除填写遗留的数据
                findCsSmOrderTypeData(); // reload the role data
                $("#smOrderTypeId").val("");//设置为空
            }else {
                closeDialog("dlgCsSmOrderType");
                showInfoTip("操作失败", "", 2000);
                $('#formCsSmOrderType').form('clear');//清除填写遗留的数据
                findCsSmOrderTypeData(); // reload the role data
                $("#smOrderTypeId").val("");//设置为空
            }
        },"POST");
    }
}

/*
设置客户信息字典值
*/
function setLabelOrderType(customerTypeSelect,customerGrade){
    var customerTypeParams = {
        headerValue:false,
        value:customerTypeSelect
    }
    var customerGradeParams = {
        headerValue:false,
        value:customerGrade
    }
    uceDictCombobox("orderLevel","WORKORDER_TYPE_LEVEL",customerTypeParams);//初始化
    uceDictCombobox("kind","WORKORDER_KIND",customerGradeParams);//初始化
}

//取消
function cancle(){
    $('#formCsSmOrderType').form('clear');//清除上一次遗留的数据
    $("#smOrderTypeId").val("");//设置为空
    level = '';
    levelTypeStatus = '';//清空数据
    closeDialog("dlgCsSmOrderType");
}

//公共的添加功能-->对窗口的内容进行初始化
function commomAdd(){
    setLabelOrderType();//初始化下拉列表
    $("#formCsSmOrderType #orderLevel").combobox({
        onSelect: function (item) {
            var coData = '';
            if (item.typeCode == 2) {
                levelTypeStatus = '2';
                    //二级分类，需要选择一级工单类型
                $("#formCsSmOrderType #pOrderTypeTr").show();
                $("#formCsSmOrderType #pOrderTypeSec").hide();
                $("#formCsSmOrderType #validTimeStr").show();
                $("#formCsSmOrderType #problemTypeStr").show();
                $("#formCsSmOrderType #startFlagStr").show();
                $("#parentIdCombobox").attr("required","true");
                var url = G_CTX_PATH + "/cs/CsSmOrderType/getCsSmOrderTypeList.do";
                $("#formCsSmOrderType #pOrderTypeTr #parentIdCombobox").combobox({
                    panelHeight: 200,
                    editable: false,
                    valueField: "idStr",
                    textField: "name",
                    prompt: "---请选择---"
                });
                $.ajax({
                    type : "POST", //提交方式
                    url : url,//路径
                    data : { type : 1 ,kind : 7},//数据，这里使用的是Json格式进行传输
                    async : false,//设置为同步
                    // dataType: 'json',
                    success : function(result) {//返回数据根据结果进行相应的处理
                        coData = result;
                    }
                });
                if(coData != ''){
                    reLoadData(coData);//重新加载数据
                }
                $('#startFlag').uceCombobox({
			        width : 300,
			        editable : false,
			        data : [ {
			            'value' : '0',
			            'text' : '否'
			        },{
			            'value' : '1',
			            'text' : '是',
			            "selected" : true
			        }]
			    });
			    $('#problemType').uceCombobox({
			        width : 300,
			        editable : false,
			        data : [{
			            'value' : '1',
			            'text' : '乾坤问题件类型'
			        },{
			            'value' : '2',
			            'text' : 'ICS手工创建',
			            "selected" : true
			        }]
			    });
            } else if (item.typeCode == 3) {
                levelTypeStatus = '3';
                    //二级分类，需要选择一级工单类型
                $("#formCsSmOrderType #pOrderTypeSec").show();
                $("#formCsSmOrderType #pOrderTypeTr").hide();
                $("#formCsSmOrderType #validTimeStr").hide();
                $("#formCsSmOrderType #problemTypeStr").hide();
                $("#formCsSmOrderType #startFlagStr").hide();
                $("#secondeIdCombobox").attr("required","true");
                var url = G_CTX_PATH + "/cs/CsSmOrderType/getCsSmOrderTypeList.do";
                $("#formCsSmOrderType #pOrderTypeSec #secondeIdCombobox").combobox({
                    panelHeight: 200,
                    editable: false,
                    valueField: "idStr",
                    textField: "name",
                    prompt: "---请选择---"
                });
                $.ajax({
                    type : "POST", //提交方式
                    url : url,//路径
                    data : { type : 2 ,kind : 7},//数据，这里使用的是Json格式进行传输
                    async : false,//设置为同步
                    // dataType: 'json',
                    success : function(result) {//返回数据根据结果进行相应的处理
                        coData = result;
                    }
                });
                if(coData != ''){
                    if(levelTypeStatus == 3 ){//如果一级变为二级，则在下拉框中不显示当前的节点
				        for ( var i = 0; i <coData.length; i++){
				            if(coData[i].idStr == targetId){
				                coData.splice(i,1);
				            }
				        }
				        $("#secondeIdCombobox").combobox('loadData',coData);//重新加载数据
				    }else {
				        $("#secondeIdCombobox").combobox('loadData',coData);//重新加载数据
				    }
                }
            }else {
                levelTypeStatus = '1';
                //一级分类，隐藏一级工单类型
                $("#formCsSmOrderType #pOrderTypeTr").hide();
                $("#formCsSmOrderType #pOrderTypeSec").hide();
                $("#formCsSmOrderType #validTimeStr").hide();
                $("#formCsSmOrderType #problemTypeStr").hide();
                $("#formCsSmOrderType #startFlagStr").hide();
                $("#parentIdCombobox").attr("required","false");
                //清除编辑中可能参生的parentId的垃圾数据
                $("#parentIdCombobox").combobox("setValue","");//设置为空
            }
        }
    });
}

//新增打开
function openCsSmOrderType(){
    openDialog("dlgCsSmOrderType", '新增问题件工单类型');
    url = G_CTX_PATH+'/cs/CsSmOrderType/addOrEdit.do';
}

//编辑打开
function editCsSmOrderType() {
    openDialog("dlgCsSmOrderType", '编辑问题件工单类型');
    url = G_CTX_PATH+'/cs/CsSmOrderType/addOrEdit.do';
}


$('#dlgCsSmOrderType').dialog({
    onClose: function () {
        level = '';
        $('#formCsSmOrderType').form('clear');//清除上一次遗留的数据
        $("#smOrderTypeId").val("");//设置为空
    }
})

/*
设置客户信息字典值
*/
function setCsSmOrderType(customerTypeSelect){
    var customerTypeParams = {
        headerValue:false,
        value:customerTypeSelect
    }
    uceDictCombobox("kindForQuery","WORKORDER_KIND",customerTypeParams);
}

//重新加载数据
function reLoadData(coData){
    if(levelTypeStatus == 2 && level == 1){//如果一级变为二级，则在下拉框中不显示当前的节点
        for ( var i = 0; i <coData.length; i++){
            if(coData[i].idStr == targetId){
                coData.splice(i,1);
            }
        }
        $("#parentIdCombobox").combobox('loadData',coData);//重新加载数据
    }else {
        $("#parentIdCombobox").combobox('loadData',coData);//重新加载数据
    }
}

</script>
<!--客服服务类工单全部列表 -->
<div id="csSmOrderTypeSer">
    <form action="#" id="formFindCsSmOrderType">
        <div id="aa" class="easyui-accordion">
            <div title="" data-options="selected:true">
                <ul class="search-form">
                    <li><input class="easyui-combobox" id ="type" label="所属分类：" labelPosition="left" labelWidth="100px"
                               name="type" data-options="prompt:'请输入所属分类'"></li>
                    <li><input class="easyui-textbox" id="typeCodeStr" label="类型编号：" labelPosition="left"
                               labelWidth="100px" name="typeCodeStr" data-options="prompt:'请输入类型编号'"></li>
                    <li><input class="easyui-textbox" id="typeNameStr" label="类型名称：" labelPosition="left"
                               labelWidth="100px" name="typeNameStr" data-options="prompt:'请输入类型名称'"></li>
                    <div style="margin-left: 38px">
                        <a href="#" class="easyui-linkbutton search" onclick="findCsSmOrderTypeData()">查询</a>
                        <a href="#" class="easyui-linkbutton reset" onclick="resetQueryForm()">重置</a>
                    </div>
                </ul>
            </div>
        </div>
        <div class="toolbar-margin">
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="iconfont icon-zengjia-w"
               onclick="addCsSmOrderType()" plain="true">新增</a>
        </div>

    </form>
</div>
<table id="dgCsSmOrderTypeSer" class="easyui-datagrid" data-options="fit:true"></table>
<!--新增修改dialog -->
<div id="dlgCsSmOrderType" class="easyui-dialog"
     style="width: 450px; height: 500px; padding: 5px" closed="true" buttons="#divRoleBtn">
    <div class="easyui-layout" data-options="fit:true">
        <div data-options="region:'center',border:false"
             style="padding: 15px 20px; background: #fff;">
            <form id="formCsSmOrderType" method="post">
                <table class="table" style="width: 400px; border: 0px;">
                  <tbody>
                    <tr style="padding-left: 20px">
                        <input type="hidden" name="id" id="smOrderTypeId">
                        <td width="80px">工单级别<span style="color: red">*</span>：</td>
                        <td  width="300px">
                            <input name="orderLevel" class="easyui-combobox" id="orderLevel"
                                   style="width:300px;height: 40px" required="true">
                        </td>
                    </tr>
                    <tr style="padding-left: 20px" id="pOrderTypeTr" style="display: none">
                        <td width="80px">一级工单类型<span style="color: red;">*</span>: </td>
                        <td width="300px">
                            <input name="parentId" id="parentIdCombobox"
                                                 class="easyui-combobox" style="width:300px;height: 40px"></td>
                    </tr>
                    
                    <tr style="padding-left: 20px" id="pOrderTypeSec" style="display: none">
                        <td width="80px">二级工单类型<span style="color: red;">*</span>: </td>
                        <td width="300px">
                            <input name="secondeId" id="secondeIdCombobox"
                                                 class="easyui-combobox" style="width:300px;height: 40px"></td>
                    </tr>
                    
                    <tr style="padding-left: 20px">
                        <td>类型编码:</td>
                        <td><input name="typeCode" id="typeCode" class="easyui-textbox" type="number"
                                   style="width:300px;height: 40px" >
                        </td>
                    </tr>
                    <tr style="padding-left: 20px">
                        <td>类型名称<span style="color: red;">*</span>:</td>
                        <td><input name="name" id="typeName" class="easyui-textbox"
                                   style="width:300px;height: 40px" required="true" >
                        </td>
                    </tr>

                    <tr style="padding-left: 20px" id="startFlagStr" style="display: none">
                        <td>是否启用<span style="color: red;">*</span>:</td>
                        <td><input id="startFlag"  name="startFlag" class="easyui-combobox"
                                   style="width:300px;height:40px;" >
                        </td>
                    </tr>
                    <tr style="padding-left: 20px" id="problemTypeStr" style="display: none">
                        <td>问题件类型<span style="color: red;">*</span>:</td>
                        <td><input id="problemType"  name="problemType" class="easyui-combobox"
                                   style="width:300px;height:40px;" >
                        </td>
                    </tr>
                    <tr style="padding-left: 20px" id="validTimeStr" style="display: none">
                        <td>有效时间<span style="color: red;">*</span>:</td>
                        <td><input name="validTime" id="validTime" class="easyui-textbox" type="number"
                                   style="width:300px;height: 40px"  >
                        </td>
                    </tr>
                    <tr>
                        <td>备注:</td>
                        <td><input name="remarks" id="remarks" class="easyui-textbox"
                                    multiline="true"
                                   style="height: 120px; width:300px"></td>
                    </tr>
                  </tbody>
                </table>
            </form>
        </div>
    </div>
</div>
<div id="divRoleBtn">
    <a href="javascript:void(0)" class="easyui-linkbutton  save" onclick="saveOrderType()">保存</a>
    <a href="javascript:void(0)" class="easyui-linkbutton call" onclick="cancle()">取消</a>
</div>
<!--工单优先级升级弹窗 结束-->
<script type="text/javascript" src="${ctx}/static/js/main.js"></script>
<script type="text/javascript" src="${ctx}/static/js/hg/hg.ui.js"></script>
</body>
</html>